cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

project(recipe-04 LANGUAGES CXX)

set(USE_LIBRARY ON)                                                 # 定义一个变量、并且初值为真
message(STATUS "Compile source into library? ${USE_LIBRARY}")       # 相当于print/cout

set(BUILD_SHARED_LIBS ON)                                  # 内置的全局标量，若add_library中不指定类型，则true-动态库、false-静态库

list(APPEND _sources Message.hpp Message.cpp)               # 引入一个局部变量指代后面内容

if (USE_LIBRARY)
    add_library(message ${_sources})                        # 配合上面的 BUILD_SHARED_LIBS ，可以省略STATIC/SHARED
    add_executable(hello-world hello-world.cpp)
    target_link_libraries(hello-world message)
else ()
    add_executable(hello-world hello-world.cpp ${_sources})
endif ()



